package cryptography;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class PrimeNumberTest {
	/** Creates a new instance of PrimeNumberTest */
	public PrimeNumberTest() {
	}

	public static void main(String[] args) {
		// 获得一个4位数的随机大素数
		long longVar4 = createRadomPrimeNunber(4);
		System.out.println(longVar4);
		// 获得一个5位数的随机大素数
		long longVar5 = createRadomPrimeNunber(5);
		System.out.println(longVar5);
		
		double l = 1;
		for(int i=0;i<9;i++)
			l *= 23;
		System.out.println(l%90731);
	}

	public static long createRadomPrimeNunber(int n) {
		long recLong = 0;
		List list = listAllPrimeNumber(n);
		Random rd = new Random();
		int randomIndex = Math.abs(rd.nextInt() % list.size());
		recLong = ((Long) list.get(randomIndex)).longValue();
		return recLong;

	}

	public static List listAllPrimeNumber(int n) {
		List list = new ArrayList();
		long low = (long) Math.pow(10, n - 1);
		long high = (long) Math.pow(10, n) - 1;
		for (long i = low; i < high; i++) {
			if (isSushu(i)) {
				list.add(new Long(i));
			}
		}
		return list;
	}

	public static boolean isSushu(long x) {// 定义一个判断一个数是否是素数的函数
		if (x < 2)
			return false;
		if (x == 2)
			return true;
		for (long i = 2; i <= (long) Math.sqrt(x); i++)
			if (x % i == 0)
				return false;
		return true;
	}
}
